package org.refresh.emf.tests;

import java.util.List;

import org.eclipse.emf.examples.extlibrary.Book;
import org.eclipse.emf.examples.extlibrary.EXTLibraryFactory;
import org.eclipse.emf.examples.extlibrary.EXTLibraryPackage;
import org.refresh.core.intelligence.emf.OCLConstraint;
import org.refresh.core.intelligence.emf.OCLConstraintEvaluator;
import org.refresh.emf.EMFIntelligence;

import junit.framework.TestCase;

/******************************************************************************
 * Copyright (c) 2005, 2006 Jules White.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Jules White - initial API and implementation 
 ****************************************************************************/
public class EMFIntelligenceTest extends TestCase {
	
	

	public void testEMFIntelligenceWithOCL(){
		
		EMFIntelligence kb = new EMFIntelligence();
		
		OCLConstraintEvaluator eval = new OCLConstraintEvaluator();
		OCLConstraint con = new OCLConstraint("not(self.title = target.title)");
		OCLConstraint con1 = new OCLConstraint("target.title = target.title");
		EXTLibraryFactory fact = EXTLibraryPackage.eINSTANCE.getEXTLibraryFactory();
		Book f1 = fact.createBook();
		Book f2 = fact.createBook();
		Book f3 = fact.createBook();
		f1.setTitle("foo");
		f2.setTitle("foo2");
		f3.setTitle("foo");
		
		kb.add(f1);
		kb.add(f2);
		kb.add(f3);
		
		kb.add(f1.eClass(), "different", f1.eClass(), con1);
		kb.add(f1.eClass(), "different", f1.eClass(), con);
		
		List valid = kb.validTargets(f1, "different");
		assertEquals(1, valid.size());
	}
}
